﻿///////////////////////////////////////////////////////////////////////////////
// Name:        chart
// Purpose:     图表
// Author:      dbian
// Modified by:
// Created:     2011-7-05
// Copyright:   (C) Copyright 2011, Dbian, All Rights Reserved.
// Licence:     wxWindows Library Licence, Version 3.1
///////////////////////////////////////////////////////////////////////////////

//stl

#pragma once

#include <math.h>
//数据
#include <vector>
//#ifdef WXMAKINGDLL_PLOT
//    #define WXDLLIMPEXP_PLOT WXEXPORT
//    #define WXDLLIMPEXP_DATA_PLOT(type) WXEXPORT type
//#elif defined(WXUSINGDLL)
//    #define WXDLLIMPEXP_PLOT WXIMPORT
//    #define WXDLLIMPEXP_DATA_PLOT(type) WXIMPORT type
//#else // not making nor using DLL
//    #define WXDLLIMPEXP_PLOT
//    #define WXDLLIMPEXP_DATA_PLOT(type) type
//#endif

class Point
{
public:
	Point(){}
	Point(double dx,double dy){x=dx;y=dy;}
	~Point(){}
	double x,y;

};


class line
{
public:
	line(  )
	{
		dline.reserve(20000);
	}
	~line(  )
	{
	}
	void add(double x,double y)
	{
		dline.push_back(new Point(x,y));
	}
	void clear()
	{
		/*for(unsigned int i=0;i!=dline.size();i++)
			delete dline[i];*/
		//这里不清理内存，留给更高层清理
		dline.clear();
	}
	std::vector<Point*> dline;
	//wxList s;
	int getSize()
	{
		return dline.size();
	}
	double getx(int index)
	{
		return dline[index]->x;
	}
	double gety(int index)
	{
		return dline[index]->y;
	}
};

class chart :public wxWindow
{
public:
	chart(wxWindow *parent,int id);
	~chart(void);
public:
	void addred(double x,double y);
	void addblue(double x,double y);

	void setData(std::vector<Point*>&data,bool isRed);
	void setData(std::vector<Point*>*dRed,std::vector<Point*>*dBlue);

	void clearAll();
	void setTitle(const wxString&t);
	void setXLabel(const wxString&t);
	void setYLabel(const wxString&t);
	//自动绘制范围,默认关
	void setAuto(bool a=false);

public:

private:
	//最多支持2个通道读取和显示
	line red, blue;

	wxBitmap buf;


private:
	bool busy;

	wxString title,xlabel,ylabel;
	//因为是画在一张图里，所以只需一个框架
	double minx,miny,maxx,maxy;
	//用来记忆实际坐标，只在需要更新最大最小值时重新计算
	std::vector<wxPoint*> virRed,virBlue;
	
	//负责转换虚拟坐标到屏幕坐标
	void refreshAll();

	void clearVir();

	void paint(wxPaintEvent & evt);

	void realDraw(wxDC&  dc);
	void onSizeEvt(wxSizeEvent&e);

	DECLARE_EVENT_TABLE()

};

